﻿using System;
using System.Collections.Generic;
using System.Text;
using FingerTip.Infrastructure.Configuration;
using FingerTip.Infrastructure.NotifyMessager.Event;

namespace FingerTip.Infrastructure.NotifyMessager
{
    public class MessageFactory
    {
        private static string BaseHost
        {
            get
            {
                var baseHost = AppSettings.Instance.GetConfig("Front:Host");
                if (string.IsNullOrEmpty(baseHost))
                {
                    baseHost = "http://fingertip.net";
                }

                return baseHost;
            }
        }

        public static Message GetMessageContent(MessageType messageType, MessageEventArgs args)
        {
            var message = InitMessage(messageType);
            switch (messageType)
            {
                case MessageType.SheetAproachNotify:
                    message.Content =
                        $"您有任务到达：{System.Environment.NewLine}站点，当前状态：【xxx】，" +
                        $"{System.Environment.NewLine}请尽快处理。";
                    break;
                case MessageType.CodeMergeFailureNotify:
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点代码合并失败，{System.Environment.NewLine} 请尽快处理.";
                    break;
                case MessageType.CodeMergeFailureSolvedNotify:
                    message.Title = $"Bugfix";
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点代码合并失败，{System.Environment.NewLine} 需要进行Bugfix修复，请尽快处理。";
                    break;
                case MessageType.BuildFailureNotify:
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点构建失败，{System.Environment.NewLine}请尽快处理。";
                    break;
                case MessageType.BuildFailureSolvedNotify:
                    message.Title = $"Bugfix";
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点构建失败，{System.Environment.NewLine}需要进行Bugfix修复，请尽快处理。";
                    break;
                case MessageType.DeployFailureNotify:
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点部署失败，{System.Environment.NewLine}请尽快处理。";
                    break;
                case MessageType.DeployFailureSolvedNotify:
                    message.Title = $"Bugfix：";
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点部署失败，{System.Environment.NewLine}需要进行Bugfix修复，请尽快处理。";
                    break;
                case MessageType.ProductDeployFailureNotify:
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点正式发布失败，{System.Environment.NewLine}请尽快处理。";
                    break;
                case MessageType.ProductDeploySuccessNotify:
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点正式发布成功，{System.Environment.NewLine}请注意关注。";
                    break;
                case MessageType.BugfixSolvedNotify:
                    message.Title = $"Bugfix";
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点" +
                        $"{System.Environment.NewLine} 需要进行Bugfix修复，请尽快处理。";
                    break;
                case MessageType.WorkItemFinishNotify:
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点工作流已完结，{System.Environment.NewLine} 请知晓。";
                    break;
                case MessageType.WorkSheetFinishNotify:
                    message.RedirectUrl = $"{BaseHost}/#/finalsheet";
                    message.Content = $"任务：{System.Environment.NewLine}全部完结，请知晓。";
                    break;
                case MessageType.ProductPublishNotify:
                    message.Content =
                        $"任务：已发布，请知晓。";
                    break;
                case MessageType.CodeReviewFailureNotify:
                    message.Content =
                        $"任务：{System.Environment.NewLine}站点，当前状态：" + $"{System.Environment.NewLine} 需要进行代码修复，请尽快处理。";
                    break;
                default:
                    break;
            }

            return message;
        }

        private static Message InitMessage(MessageType messageType)
        {
            var message = new Message
            {
                MessageType = messageType,
                RedirectUrl = BaseHost,
            };
            return message;
        }

        private static List<string> GetReceivers(MessageType messageType)
        {
            return null;
        }
    }
}
